﻿using System.Collections;

namespace IceDog.DNL.CSharp.DesignPattern.PrototypePattern.WorldShapeClone
{
    /// <summary>
    /// 图形类型
    /// </summary>
    public enum ShapeType
    {
        Circle,
        Rectangle,
        Square
    }

    /// <summary>
    /// 
    /// </summary>
    public static class ShapeCache
    {
        private static readonly Hashtable Table = new Hashtable();
        //使用 GetShape 方法获取形状类型的对象
        public static Shape GetShape(string shapeId)
        {
            Shape shape = Table[shapeId] as Shape;
            return shape?.Clone() as Shape;
        }

        public static void LoadCache()
        {
            Shape s1 = new Circle(){Id = "1"};
            Table.Add(s1.Id,s1);
            Shape s2 = new Square() { Id = "2" };
            Table.Add(s2.Id, s2);
            Shape s3 = new Rectangle() { Id = "3" };
            Table.Add(s3.Id, s3);
        }
    }
}

